package com.lianzhihui.romeex.ui.me.dialog;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.ui.base.BaseDialog;
import com.lianzhihui.romeex.utils.ImagesUtil;
import com.lianzhihui.romeex.utils.NoDoubleClickUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.ui.me.dialog
 * @ClassName: UpDateVersionDialog
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/3 10:40
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/3 10:40
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class ShareDialog extends BaseDialog {


    @BindView(R.id.qr_code)
    ImageView qrCode;
    @BindView(R.id.root_layout)
    FrameLayout rootLayout;
    @BindView(R.id.qr_content)
    TextView qr_content;

    SaveCallback callback;
    String inviteCode;
    private final String loadUrl = "https://d.riceex.com/";

    public ShareDialog(@NonNull Context context, String inviteCode) {
        super(context);
        this.inviteCode = inviteCode;
    }

    public ShareDialog(Context context, int style) {
        super(context, style);
    }

    @Override
    public void setCancelable(boolean flag) {
        super.setCancelable(flag);
    }


    public void setCallback(SaveCallback callback) {
        this.callback = callback;
    }

    @Override
    public void show() {
        super.show();
        if (null != qrCode && inviteCode != null) {
//            ImagesUtil.createQrCodeImg(QRUtils.type4 + inviteCode, qrCode, 500);
            ImagesUtil.createQrCodeImg(loadUrl, qrCode, 500);
            qr_content.setText(inviteCode);

        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_share;
    }

    @Override
    protected void initView() {

    }


    @OnClick({R.id.tv_save_image, R.id.iv_close})
    public void OnClick(View v) {
        if (NoDoubleClickUtils.isDoubleClick()) {
            switch (v.getId()) {
                case R.id.tv_save_image:
                    if (null != callback) {
                        callback.save(rootLayout);
                    }
                    break;
                case R.id.iv_close:
                    dismiss();
                    break;
                default:
                    break;
            }
        }
    }

    public interface SaveCallback {
        void save(View v);
    }


}
